package com.snail.billing.session;

import com.snail.billing.DataCache;
import com.snail.billing.net.BillingHttpSession;
import com.snail.billing.net.BillingSecurity;

public class PayOneSession extends BillingHttpSession {

	public PayOneSession() {
		DataCache cache = DataCache.getInstance();
		String host = cache.importParams.hostImprest;
		String formatUrl = null;
		BillingSecurity security = getSecurity();
		if (cache.importParams.isAccess) {
			formatUrl = "http://%s/app/" + security.accessId + "/" + security.accessType + "/order/create";
		} else {
			formatUrl = "http://%s/app/order/create";
		}
		String address = String.format(formatUrl, host);
		setAddress(address);
		addParamPair("productName", cache.paymentParams.card.getCardName());
		addParamPair("cardTypeId", String.valueOf(cache.paymentParams.card.getId()));
		addParamPair("paymentId", String.valueOf(cache.paymentParams.platformId));
		addParamPair("captchaValue", cache.paymentParams.captchaValue);
		addParamPair("random", cache.paymentParams.random);
		addParamPair("amount", String.valueOf(cache.paymentParams.amount));
		//
		addParamPair("gameId", cache.importParams.gameId);
		addParamPair("imprestDestination", cache.importParams.imprestDestination);
		if (cache.importParams.imprestDestination.equals("1")) {
			addParamPair("areaId", "0");
		} else if (cache.importParams.imprestDestination.equals("2")) {
			addParamPair("areaId", cache.paymentParams.areaId);
		}
		addParamPair("passport", cache.importParams.account);
		addParamPair("retypePassport", cache.importParams.account);
	}

	@Override
	public BillingSecurity getSecurity() {
		if (DataCache.getInstance().isSandbox) {
			return BillingSecurity.securitySandbox;
		}
		return BillingSecurity.security;
	}
}
